package com.yangye.springclouddemoclient.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.converters.Auto;
import com.yangye.springclouddemoclient.client.HelloFeignClient;
import com.yangye.springclouddemoclient.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author Page.Yang
 * @date 2019/3/21 0021
 */
@RestController
@EnableEurekaClient
public class HelloController {

	@Autowired
	private HelloService helloService;

	@Autowired
	private RestTemplate restTemplate;

	@Autowired
	private HelloFeignClient helloFeignClient;

	@Autowired
	private DiscoveryClient discoveryClient;

	@GetMapping("/hello")
	public String hello() {
		ResponseEntity<String> forEntity = restTemplate.getForEntity("http://provider-service/hello", String.class);
		return forEntity.getBody();
	}

	@GetMapping("/feignHello")
	public String feignHello() {
		return helloFeignClient.hello();
	}

	@GetMapping("/allClients")
	public List<ServiceInstance> listAllClients() {
		List<ServiceInstance> provider = discoveryClient.getInstances("PROVIDER-SERVICE");
		return provider;
	}

}
